/*
 * @Author: Wangtao
 * @Date: 2020-09-18 11:41:07
 * @LastEditors: zhanwang
 * @LastEditTime: 2021-07-21 14:53:01
 */
import Vue from 'vue'
import App from './App.vue'
import router from './router/handleRoute'
import store from './store'
import ElementUI from 'element-ui'
import '../theme/index.css'
import './assets/iconfont/iconfont.css'
import preview from '@/afterSales/components/preview/index'
import './assets/iconfont/iconfont.js' // 多色图标
import './common/style/element.styl' // v7全局自定义的element样式
import './common/style/afterSales.styl'
import './assets/mopower.styl' // 修改 mopower 的样式
import { Component } from 'vue-property-decorator'
// import VueI18n from 'vue-i18n'
import { UTable, UTableColumn } from 'umy-ui'
import EventBus from 'vue-bus-ts'
import m7getCache from '@/utils/m7getCache'
import PortalVue from 'portal-vue'
// import 'umy-ui/lib/theme-chalk/index.css'

/***
 * 售后云start
 */
import '@/afterSales/businessConfig/initFlowImport'
/***
 * 售后云end
 */
/**
 * 自定义指令
 */
import directives from '@/utils/directive'
import '@components/IconSvg' // 全局icon 多色图标组件
import '@/components/select' // 全局的m7select组件
import '@/utils/addZhuGeTrack' // 诸葛IO埋点
import '@/components/globalTool/index' // 全局指令
Vue.config.productionTip = false
Vue.config.devtools = true
Vue.use(UTable)
Vue.use(PortalVue)
Vue.use(preview)
Vue.use(UTableColumn)
Vue.use(ElementUI, {
  zIndex: 1800
})
// Vue.use(VueI18n)
Vue.use(EventBus)
Vue.use(m7getCache)

Vue.use(directives)
const bus = new EventBus.Bus()
let app: any = null
// 组件内的路由钩子
/**
 * 渲染函数
 * appContent 子应用html内容
 * loading 子应用加载效果，可选
 */
function render ({ appContent, loading }: any = {}) {
  // console.log('render:\n', appContent, loading)
  if (!app) {
    app = new Vue({
      el: '#main-container',
      store,
      router,
      bus,
      data () {
        return {
          content: appContent,
          loading
        }
      },
      render (h) {
        return h(App, {
          props: {
            // content: this.content,
            // loading: this.loading
          }
        })
      }
    })
  } else {
    app.content = appContent
    app.loading = loading
  }
}

function initApp () {
  render({ appContent: '', loading: false })
}

initApp()

Component.registerHooks([
  'beforeRouteEnter', // 路由进入组件时，实例还没有创建，无法获取到this
  'beforeRouteLeave', // 导航离开组件的对应路由时调用,能获取到this
  'beforeRouteUpdate' // 路由修改，当前组件被复用时调用,能获取到this
])
